package com.exam.sacrifice.ui.adapter;

import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.exam.sacrifice.R;
import com.exam.sacrifice.ui.bean.RechargeInfo;

public class RechargeCenterAdapter extends BaseQuickAdapter<RechargeInfo, BaseViewHolder> {

    private OnItemClickListener listener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        listener = onItemClickListener;
    }

    public RechargeCenterAdapter() {
        super(R.layout.item_layout_recharge_center, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, RechargeInfo item) {

        LinearLayout llContainer = helper.getView(R.id.ll_container);
        TextView tvFee = helper.getView(R.id.tv_fee);
        tvFee.setText(item.fee);
        helper.setText(R.id.tv_note, item.note);

        if (item.checked == 1) {
            tvFee.setTextColor(helper.itemView.getContext().getColor(R.color.main_color));
            llContainer.setBackground(helper.itemView.getContext().getDrawable(R.drawable.shape_maincolor_out_12));
        } else {
            tvFee.setTextColor(helper.itemView.getContext().getColor(R.color.black));
            llContainer.setBackground(helper.itemView.getContext().getDrawable(R.drawable.shape_e5e7eb_out_12));
        }
        helper.itemView.setOnClickListener(v -> {
            if (listener != null) {
                listener.onItemClick(item);
            }
        });
    }

    public void clear() {
        for (int i = 0; i < getData().size(); i++) {
            getData().get(i).checked = 0;
        }
    }

    public interface OnItemClickListener {
        void onItemClick(RechargeInfo messageInfo);
    }
}
